package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketFootprint;
import com.cskaoyan.market.db.domain.MarketFootprintExample;
import com.cskaoyan.market.db.mapper.MarketFootprintMapper;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 付诚
 * @Date: 2024/5/6 21:27
 * @Description:
 */
@Service
public class MarketFootprintServiceImpl implements MarketFootprintService {

    @Autowired
    private MarketFootprintMapper marketFootprintMapper;

    @Override
    public List<MarketFootprint> list(Integer page, Integer limit, String userId, String goodsId, String sort, String order) {

        MarketFootprintExample marketFootprintExample = new MarketFootprintExample();
        marketFootprintExample.setOrderByClause(sort + " " + order);
        MarketFootprintExample.Criteria criteria = marketFootprintExample.createCriteria();
        if (!StringUtils.isEmpty(userId)) {
            criteria.andUserIdEqualTo(Integer.parseInt(userId));
        }
        if (!StringUtils.isEmpty(goodsId)) {
            criteria.andGoodsIdEqualTo(Integer.parseInt(goodsId));
        }

        //两个参数：当前页；每页数量
        PageHelper.startPage(page, limit);

        List<MarketFootprint> marketFootprintList = marketFootprintMapper.selectByExample(marketFootprintExample);
        return marketFootprintList;
    }
}
